import _thread
import sys
import time
from common.utility import Utility

# 主函数
def main(thread_count: int = 500):
    global count, thread_finished_count
    Utility.print_info('entered.')
    thread_ids: list[int] = []
    for i in range(thread_count):
        thread_ids.append(start_thread())
    while True:
        if thread_finished_count == thread_count:
            break
        time.sleep(0.00001)
    Utility.print_info(f'exited. count is {count}.')

# 创建线程
def start_thread() -> int:
    return _thread.start_new_thread(task, ())

# 任务
def task() -> None:
    global count, thread_finished_count, event
    with lock:
        count = count + count*10 + count*90 - count*100 + 1
        thread_finished_count += 1

print(f'is gil enabled: {sys._is_gil_enabled()}')
print(f'python version: {sys.version}')
count: int = 0
thread_finished_count: int = 0
event: _thread.LockType = _thread.allocate_lock()
main(50000)
